<?php

namespace App\Policies;

use App\User;
use App\Models\EduTopic;
use Illuminate\Auth\Access\HandlesAuthorization;

class EduTopicPolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the user can view the edu topic.
     *
     * @param  \App\User  $user
     * @param  \App\Models\EduTopic  $eduTopic
     * @return mixed
     */
    public function view(User $user, EduTopic $eduTopic)
    {
        //
    }
//通过定义模型策略的zan方法,对用户在对模型策略点赞时候的验证
    public function zan (User $user ,EduTopic $topic){
        return $user->id != $topic->user_id ;
//        return  $user['id']  != $topic['user_id'];
    }
    //通过定义模型策略的store方法,对用户进行模型策略收藏时候的验证
    public function store (User $user ,EduTopic $topic){
        //通过调用集合对象的pluck()方法可以从集合中单独拿出一列数据
//        dd($user->getAllPermissions()->pluck('name')->toArray());
        //限制当前用户不能收藏自己的帖子
        //限制拥有Edu-Topic权限的用户可以收藏任何帖子
        return $user['id'] != $topic['user_id'] || $user->can('Edu-topic');
    }
    /**
     * Determine whether the user can create edu topics.
     *
     * @param  \App\User  $user
     * @return mixed
     */
    public function create(User $user)
    {
        //
    }

    /**
     * Determine whether the user can update the edu topic.
     *
     * @param  \App\User  $user
     * @param  \App\Models\EduTopic  $eduTopic
     * @return mixed
     */
    public function update(User $user, EduTopic $topic)
    {
        return $user['id'] == $topic['user_id'] || $user->can('Edu-topic') ;
    }

    /**
     * Determine whether the user can delete the edu topic.
     *
     * @param  \App\User  $user
     * @param  \App\Models\EduTopic  $eduTopic
     * @return mixed
     */
    public function delete(User $user, EduTopic $topic)
    {
        return $user['id'] == $topic['user_id']  || $user->can('Edu-topic');
    }

    /**
     * Determine whether the user can restore the edu topic.
     *
     * @param  \App\User  $user
     * @param  \App\Models\EduTopic  $eduTopic
     * @return mixed
     */
    public function restore(User $user, EduTopic $eduTopic)
    {
        //
    }

    /**
     * Determine whether the user can permanently delete the edu topic.
     *
     * @param  \App\User  $user
     * @param  \App\Models\EduTopic  $eduTopic
     * @return mixed
     */
    public function forceDelete(User $user, EduTopic $eduTopic)
    {
        //
    }


}
